package com.neusoft.ysu.npms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neusoft.ysu.npms.pojo.FarmerInfo;
import com.neusoft.ysu.npms.mapper.FarmerMapper;
import com.neusoft.ysu.npms.pojo.*;
import com.neusoft.ysu.npms.pojo.Result;
import com.neusoft.ysu.npms.service.IFarmerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 作者：刘金秋
 * @since 2024-06-18
 */
@Service
public class FarmerServiceImpl extends ServiceImpl<FarmerMapper, Farmer> implements IFarmerService {
    @Autowired
    FarmerMapper farmerMapper;

    @Override
    public Result add(Farmer farmer) {
        return new Result<>(0, "", farmerMapper.add(farmer));
    }

    @Override
    public Result deleteFarmer(Farmer farmer){
        return new Result<>(0,"",farmerMapper.deleteFarmer(farmer));
    }

    @Override
    public Result updateFarmer(Farmer farmer){
        return new Result<>(0,"",farmerMapper.updateFarmer(farmer));
    }

    @Override
    public Result selectAll(){
        return new Result<>(0,"",farmerMapper.selectAll());
    }
    @Override
    public Result findById(Farmer farmer){
        return new Result<>(0,"",farmerMapper.findById(farmer));
    }

    @Override
    public Integer findByName(Farmer farmer) {

        Farmer farmer1 = farmerMapper.findByName(farmer);
//        QueryWrapper<Farmer> queryWrapper =new QueryWrapper<>();
//        queryWrapper.eq("name",farmer.getName());
//        Farmer farmer1 = farmerMapper.selectOne(queryWrapper);
//        System.out.println(farmer1.getFarmerid());
        return farmer1.getFarmerid();
    }
    @Override
    public PageInfo getlist(Farmer farmer, int pageNum, int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        List<Farmer> infos=farmerMapper.getlist(farmer);
        return new PageInfo(infos);
    }
    @Override
    public PageInfo getlist1(FarmerPlus farmerPlus, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<FarmerPlus> infos=farmerMapper.getlist1(farmerPlus);
        return new PageInfo(infos);
    }

    @Override
    public List<Farmer> searchByArea(Farmer farmer){
        List<Farmer> farmers=farmerMapper.searchByArea(farmer);
        return farmers;
    }

    @Override
    public  List<FarmerRisk> searchRisk(FarmerRisk farmer){
        List<FarmerRisk> farmers=farmerMapper.searchRisk(farmer);
        return farmers;
    }

}
